<template>
  <div class="category-item" @click="goToCategory">
    <div class="category-content">
      <div class="category-icon-small">
        <span v-if="category.icon">{{ category.icon }}</span>
        <el-icon v-else><Shop /></el-icon>
      </div>
      <div class="category-info">
        <div class="category-name">{{ category.categoryName }}</div>
        <div class="category-count" v-if="showCount && category.productCount">
          {{ category.productCount }} 件
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { Shop } from '@element-plus/icons-vue'
import { useRouter } from 'vue-router'

const props = defineProps({
  category: {
    type: Object,
    required: true
  },
  showCount: {
    type: Boolean,
    default: false
  }
})

const router = useRouter()

// 跳转到分类页面
const goToCategory = () => {
  router.push(`/category/${props.category.id}`)
}
</script>

<style lang="scss" scoped>
.category-item {
  background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
  border-radius: 12px;
  padding: 20px;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  border: 2px solid transparent;
  height: 100%;
  min-height: 80px;
  display: flex;
  align-items: center;

  &:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(64, 158, 255, 0.15);
    border-color: #409EFF;
    background: linear-gradient(135deg, #fff5f0 0%, #ffe8dc 100%);
    
    .category-icon-small {
      background: linear-gradient(135deg, #ff9a76 0%, #ff6b35 100%);
      transform: scale(1.1);
    }

    .category-name {
      color: #ff6b35;
    }
  }

  .category-content {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 15px;
  }

  .category-icon-small {
    width: 42px;
    height: 42px;
    min-width: 42px;
    border-radius: 10px;
    background: linear-gradient(135deg, #ffa94d 0%, #ff8c42 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 18px;
    transition: all 0.3s;
    box-shadow: 0 2px 8px rgba(255, 140, 66, 0.3);

    .el-icon {
      font-size: 20px;
    }
  }

  .category-info {
    flex: 1;
    text-align: left;
    overflow: hidden;
  }

  .category-name {
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 4px;
    color: #303133;
    transition: color 0.3s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .category-count {
    font-size: 12px;
    color: #909399;
    font-weight: 400;
  }
}

// 响应式调整
@media (max-width: 768px) {
  .category-item {
    padding: 15px;
    min-height: 70px;

    .category-icon-small {
      width: 36px;
      height: 36px;
      min-width: 36px;
      font-size: 16px;

      .el-icon {
        font-size: 18px;
      }
    }

    .category-name {
      font-size: 15px;
    }
  }
}
</style>